/*
 * Copyright 2019 The FATE Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// automatically generated by the FlatBuffers compiler, do not modify

package com.webank.ai.fate.core.io;

import com.google.flatbuffers.FlatBufferBuilder;
import com.google.flatbuffers.Table;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

@SuppressWarnings("unused")
public final class Range extends Table {
    public static Range getRootAsRange(ByteBuffer _bb) {
        return getRootAsRange(_bb, new Range());
    }

    public static Range getRootAsRange(ByteBuffer _bb, Range obj) {
        _bb.order(ByteOrder.LITTLE_ENDIAN);
        return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb));
    }

    public static int createRange(FlatBufferBuilder builder,
                                  int startOffset,
                                  int endOffset) {
        builder.startObject(2);
        Range.addEnd(builder, endOffset);
        Range.addStart(builder, startOffset);
        return Range.endRange(builder);
    }

    public static void startRange(FlatBufferBuilder builder) {
        builder.startObject(2);
    }

    public static void addStart(FlatBufferBuilder builder, int startOffset) {
        builder.addOffset(0, startOffset, 0);
    }

    public static int createStartVector(FlatBufferBuilder builder, byte[] data) {
        builder.startVector(1, data.length, 1);
        for (int i = data.length - 1; i >= 0; i--) builder.addByte(data[i]);
        return builder.endVector();
    }

    public static void startStartVector(FlatBufferBuilder builder, int numElems) {
        builder.startVector(1, numElems, 1);
    }

    public static void addEnd(FlatBufferBuilder builder, int endOffset) {
        builder.addOffset(1, endOffset, 0);
    }

    public static int createEndVector(FlatBufferBuilder builder, byte[] data) {
        builder.startVector(1, data.length, 1);
        for (int i = data.length - 1; i >= 0; i--) builder.addByte(data[i]);
        return builder.endVector();
    }

    public static void startEndVector(FlatBufferBuilder builder, int numElems) {
        builder.startVector(1, numElems, 1);
    }

    public static int endRange(FlatBufferBuilder builder) {
        int o = builder.endObject();
        return o;
    }

    public void __init(int _i, ByteBuffer _bb) {
        bb_pos = _i;
        bb = _bb;
    }

    public Range __assign(int _i, ByteBuffer _bb) {
        __init(_i, _bb);
        return this;
    }

    public int start(int j) {
        int o = __offset(4);
        return o != 0 ? bb.get(__vector(o) + j * 1) & 0xFF : 0;
    }

    public int startLength() {
        int o = __offset(4);
        return o != 0 ? __vector_len(o) : 0;
    }

    public ByteBuffer startAsByteBuffer() {
        return __vector_as_bytebuffer(4, 1);
    }

    public ByteBuffer startInByteBuffer(ByteBuffer _bb) {
        return __vector_in_bytebuffer(_bb, 4, 1);
    }

    public int end(int j) {
        int o = __offset(6);
        return o != 0 ? bb.get(__vector(o) + j * 1) & 0xFF : 0;
    }

    public int endLength() {
        int o = __offset(6);
        return o != 0 ? __vector_len(o) : 0;
    }

    public ByteBuffer endAsByteBuffer() {
        return __vector_as_bytebuffer(6, 1);
    }

    public ByteBuffer endInByteBuffer(ByteBuffer _bb) {
        return __vector_in_bytebuffer(_bb, 6, 1);
    }
}

